You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
754 B
20 lines
754 B
import { getCache, setCache } from "#server/utils/context";
|
|
import { getTaskById, getRecentExecutions } from "../../../service/scheduler";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const id = getRouterParam(event, "id");
|
|
if (!id) return R.throwError(400, "Missing id", null);
|
|
|
|
const cacheKey = `scheduler:task:${id}`
|
|
const cached = await getCache<{ task: unknown, recentExecutions: unknown[] }>(cacheKey)
|
|
if (cached) return R.success(cached)
|
|
|
|
const task = await getTaskById(id);
|
|
if (!task) return R.throwError(404, "Task not found", null);
|
|
|
|
const recentExecutions = await getRecentExecutions(id, 20);
|
|
|
|
const result = { task, recentExecutions }
|
|
await setCache(cacheKey, result, 60)
|
|
return R.success(result);
|
|
});
|